﻿using AutoMapper;
using Common.Domain;
using Common.Infrastructure.Repository;
using Common.Services;
using MediatR;

namespace Business.WriteAPI.Application.Slaughtes
{
    public class SlaughteQUpdRequestHandler : IRequestHandler<SlaughteQUpdRequestModel, APIResult>
    {
        private IBaseRepository<SlaughteEnterprise> slaughteRepository;
        private readonly IMapper mapper;
        public SlaughteQUpdRequestHandler(IBaseRepository<SlaughteEnterprise> slaughteRepository, IMapper mapper)
        {
            this.slaughteRepository = slaughteRepository;
            this.mapper = mapper;
        }
        public Task<APIResult> Handle(SlaughteQUpdRequestModel request, CancellationToken cancellationToken)
        {
            APIResult result = new APIResult();
            result.Code = EnumCode.UpdSuccess;
            result.Msg = "编辑成功";

            SlaughteEnterprise slaughte = mapper.Map<SlaughteEnterprise>(request);
            slaughteRepository.Update(slaughte);

            return Task.FromResult(result);
        }
    }
    public class SlaughteQUpdRequestModel:IRequest<APIResult>
    {
        public int Id { get; set; }
        public string ProductCode { get; set; }
        public string Name { get; set; }
        public DateTime FoundTime { get; set; }
        public string Address { get; set; }
        public string Summary { get; set; }
        public string Creator { get; set; }
        public DateTime CreateTime { get; set; }
    }
}
